import java.util.PriorityQueue;
import java.util.concurrent.ThreadPoolExecutor;


class MyTimertask{
    private long time;
    private Runnable runnable;
    public MyTimertask(Runnable runnable,long delay){
        this.runnable=runnable;
        this.time=System.currentTimeMillis()+delay;
    }
    public void run(){
        runnable.run();
    }

    public long getTime() {
        return time;
    }
}


class MyTimer{
    private Thread t=null;
    private PriorityQueue<MyTimertask> queue=new PriorityQueue<>();
    private Object locker=new Object();
    public void schedule(Runnable runnable,long delay){
       synchronized (locker){
           MyTimertask task=new MyTimertask(runnable,delay);
           queue.offer(task);
       }
       locker.notify();
    }

    public MyTimer(){
        t=new Thread(()->{
          while (true){
             synchronized (locker){
                 try{
                     while (queue.isEmpty()){
                         //等待
                         locker.wait();
                     }
                     MyTimertask task=queue.peek();
                     long curTime=System.currentTimeMillis();
                     if (curTime>=task.getTime()){
                         queue.poll();
                         task.run();
                     } else {
                        locker.wait(task.getTime()-curTime);
                     }
                 }catch (InterruptedException e) {
                     e.printStackTrace();
                 }
             }
          }
        });
    }
}
public class Test {
    public static void main(String[] args) {
        MyTimer timer=new MyTimer();
        timer.schedule(new Runnable() {
            @Override
            public void run() {
                System.out.println("3000");
            }
        },3000);
    }
    ThreadPoolExecutor threadPoolExecutor=new ThreadPoolExecutor(10,20,30,41,)
}
